/*
 * // +-------------------------------------------------------------------------------------------------
 * // |                 有你就好 [ 有节骨乃坚，无心品自端 ]     <http://encoding.wang>
 * // +-------------------------------------------------------------------------------------------------
 * // |                             独在异乡为异客         每逢佳节倍思亲
 * // +-------------------------------------------------------------------------------------------------
 * // |                 联系:   <707069100@qq.com>      <http://weibo.com/513778937>
 * // +-------------------------------------------------------------------------------------------------
 */

// -----------------------------------------------------------------------------------------------------
// +----------------------------------------------------------------------------------------------------
// |                   ErYang出品 属于小极品          共同学习    共同进步
// +----------------------------------------------------------------------------------------------------
// -----------------------------------------------------------------------------------------------------


package wang.encoding.mroot.common.util;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 正则表达式工具类
 *
 * @author ErYang
 */
public class RegexUtil {

    private static final Logger logger = LoggerFactory.getLogger(RegexUtil.class);


    /**
     * 匹配中文、字母、数字和下划线
     */
    public static final String CN_LETTER_NUM_UL_REGEX = "^[a-zA-Z0-9_\\u4e00-\\u9fa5]+$";

    /**
     * 匹配中文、字母、数字和下划线 5到18位
     */
    public static final String CN_LETTER_NUM_UL_5TO18_REGEX = "^[a-zA-Z0-9_\\u4e00-\\u9fa5]{5,18}$";

    /**
     * 匹配中文、字母、数字和下划线 2到8位
     */
    public static final String CN_LETTER_NUM_UL_2TO8_REGEX = "^[a-zA-Z0-9_\\u4e00-\\u9fa5]{2,8}$";

    /**
     * 匹配中文、字母、数字和下划线 2到18位
     */
    public static final String CN_LETTER_NUM_UL_2TO18_REGEX = "^[a-zA-Z0-9_\\u4e00-\\u9fa5]{2,18}$";

    /**
     * 匹配字母、数字 6到18位
     */
    public static final String LETTER_NUM_6TO18_REGEX = "^[a-zA-Z0-9]{6,18}$";

    /**
     * 匹配中文 2到4位
     */
    public static final String CN_2TO4_REGEX = "^[\\u4e00-\\u9fa5]{2,4}$";

    /**
     * 手机号码
     */
    public static final String PHONE_NUM_REGEX = "^1[3,5,7,8]{1}[0-9]{1}[0-9]{8}$";

    /**
     * 禁止实例化
     */
    private RegexUtil() {
    }

    // -------------------------------------------------------------------------------------------------

    /**
     * 验证正则表达式
     *
     * @param source 待验证字符
     * @param regexp 验证规则
     * @return 如果待验证字符符合要求返回真, 否则返回假
     */
    public static Boolean regexValidate(final String source, final String regexp) {
        Pattern p = Pattern.compile(regexp);
        Matcher m = p.matcher(source);
        return m.matches();
    }

    // -------------------------------------------------------------------------------------------------

}

// -----------------------------------------------------------------------------------------------------

// End RegexUtil class

/* End of file RegexUtil.java */
/* Location: ./src/main/kotlin/wang/encoding/common/util/RegexUtil.java */

// -----------------------------------------------------------------------------------------------------
// +----------------------------------------------------------------------------------------------------
// |                           ErYang出品 属于小极品  O(∩_∩)O~~   共同学习    共同进步
// +----------------------------------------------------------------------------------------------------
// -----------------------------------------------------------------------------------------------------
